home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 805 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: newsfeed.gsfc.nasa.gov!usenet
  2. From: John Hannon <hannon>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What is '?' in C mean....?????
  5. Date: 9 Jan 1996 13:41:37 GMT
  6. Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA
  7. Message-ID: <4ctrah$aoc@post.gsfc.nasa.gov>
  8. References: <4cgsa8$bm2@wumpus.cc.uow.edu.au> <fcusack-0401961115540001@mudskipper.cac.psu.edu> <4ci5bb$8m4@www.gnofn.org>
  9. NNTP-Posting-Host: acrobat.gsfc.nasa.gov
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (X11; I; IRIX 5.3 IP12)
  14. X-URL: news:4ci5bb$8m4@www.gnofn.org
  15.  
  16. clm01@www.gnofn.org (Christopher L Mayeux) wrote:
  17. > frank. (fcusack@tdx.org) wrote:
  18. >: > Could anyone here explain to me what is "?" means and what the purpose
  19. >: of using
  20. >:
  21. >: ? : is C's ternary operator. if the condition is met, perform the
  22. >: operation after the ?; if the condition is not met, perform the operation
  23. >: after the :
  24. >:
  25. >
  26. >What new perversion of C is that ???
  27. >
  28. >I've been programming in standard C for 12 years, and
  29. >never saw THAT in the manuals.
  30. >-- 
  31. >------------------------------------------------------------------------------
  32. >C.L. Mayeux - Owner, MSB Video <clm01@gnofn.org> - Affordable consumer videos.
  33.  
  34.  
  35. In K & R II, p. 51: 
  36.  
  37. ". . . the ternary operator "?:" provides an alternate way . . .
  38. In the expression 
  39.  
  40.    expr1 ? expr2 : expr3
  41.  
  42. the expression expr1 is evaluated first. If it is non-zero (true), then the
  43. expression expr2 is evaluated, and that is the value. Otherwise expr3 is
  44. evaluated, and that is the value. Only one of expr2 and expr3 is evaluated.
  45. Thus to set z to the maximum of a and b,
  46.  
  47.    z = (a > b) ? a : b; /* z = max(a,b) */
  48. -- 
  49. _____________________________________
  50. |John Hannon                         |
  51. |General Sciences Corp 301-352-2123  |
  52. |MODIS Characterization Support Team |
  53. |hannon@acrobat.gsfc.nasa.gov        |
  54. |____________________________________|
  55.  
  56.